package com.test.app.login;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

import com.test.app.componentbase.ServiceFactory;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

public class UserFragment extends Fragment {

    Button btnLogin;

    private AccountService accountService;

    public UserFragment() {

    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        accountService = new AccountService();
        ServiceFactory.getInstance().setAccountService(accountService);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.login_fragment_user, container, false);
        btnLogin = view.findViewById(R.id.btn_login);
        btnLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                accountService.login("1003");
                Toast.makeText(getActivity(), "登录成功，账号是："+accountService.getAccountId(), Toast.LENGTH_SHORT).show();
            }
        });
        return view;
    }
}
